www.gusucode.com > VC++网络版的打字软件源程序-源码程序 > VC++网络版的打字软件源程序-源码程序\code\TypeClt V2.0\NetTypeTestView.cpp

    //Download by http://www.NewXing.com
// NetTypeTestView.cpp : implementation file
//

#include "stdafx.h"
#include "type.h"
#include "TypeDoc.h"
#include "NetTypeTestView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CNetTypeTestView

IMPLEMENT_DYNCREATE(CNetTypeTestView, CTypeOperatorView)

CNetTypeTestView::CNetTypeTestView()
{
}

CNetTypeTestView::~CNetTypeTestView()
{
	KillTimer(TIMER_SEND_SCORE_ID);
}


BEGIN_MESSAGE_MAP(CNetTypeTestView, CTypeOperatorView)
	//{{AFX_MSG_MAP(CNetTypeTestView)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetTypeTestView drawing

void CNetTypeTestView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
	CRect rc;
	GetClientRect(rc);

	/*双缓存
	CRect rect=rc;
	CDC		memDC;
	CBitmap memBMP;
	memDC.CreateCompatibleDC(pDC);
	memBMP.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());
	CBitmap*pOldBMP=memDC.SelectObject(&memBMP);
	SetRect(rc);
	DrawPage(&memDC,m_nCurPage);
	pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
	*/
	
	SetRect(rc);
	DrawPage(pDC,GetCurPage());
}

/////////////////////////////////////////////////////////////////////////////
// CNetTypeTestView diagnostics

#ifdef _DEBUG
void CNetTypeTestView::AssertValid() const
{
	CView::AssertValid();
}

void CNetTypeTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CNetTypeTestView message handlers
///////////////////////////////////////////////////////////
//重载保存成绩函数
void CNetTypeTestView::SaveScore(int nRate, int nSpeed)
{
	CTypeDoc* pDoc=(CTypeDoc*)GetDocument();
	pDoc->AddScore(pDoc->m_strID,pDoc->m_strName,nRate,nSpeed);

	pDoc->SendScore(nRate,nSpeed,TRUE);
	CString str;
	str.Format("您的成绩是:正确率%d%%,速度%d个/分,现已发送到教师机。",nRate,nSpeed);
	MessageBox(str,"提示信息",MB_OK | MB_ICONINFORMATION);
}

//重载开始测试
void CNetTypeTestView::BeginTest()
{
	CTypeOperatorView::BeginTest();
	SetTimer(TIMER_SEND_SCORE_ID,5000,NULL);
}

//重载结束测试
void CNetTypeTestView::EndTest()
{
	KillTimer(TIMER_SEND_SCORE_ID);
	CTypeOperatorView::EndTest();
}

/////////////////////////////////////////////////////////////
void CNetTypeTestView::OnInitialUpdate() 
{
	CTypeOperatorView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	
	/*过滤TAB键(0x09)和换行符(0x0D,0x0A)*/
	CString str;
	str.Format("%c%c%c",0x09,0x0D,0x0A);
	SetFilterChars(str);
	
	/*载入试题*/
	CTypeDoc* pDoc=(CTypeDoc*)GetDocument();
	LoadQuestion(
		pDoc->GetQuestion(),
		pDoc->GetQuestionInfo(),
		pDoc->GetTestTime(),
		pDoc->GetInputLanguage());
	
}

void CNetTypeTestView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CTypeOperatorView::OnTimer(nIDEvent);
	
	CTypeDoc* pDoc=(CTypeDoc*)GetDocument();
	CString str;

	switch(nIDEvent)
	{
	case TIMER_SEND_SCORE_ID:
		Count(str);
		pDoc->SendScore(GetRate(),GetSpeed());
		break;
	case TIMER_SAVE_SCORE_ID:
		Count(str);
		pDoc->SendScore(GetRate(),GetSpeed(),TRUE);
		break;
	}

}